package com.grieous.wow.common;

import java.util.Calendar;

public class QuickSort {
	public static void sort(int left,int right,int arr[]){
		int l=left;
		int r=right;
		int pivot=arr[(left+right)/2];
		int temp=0;
		
		while(l<r){
			while(arr[l]<pivot) l++;
			while(arr[r]>pivot) r--;
			
			if(l>=r)break;
			
			temp=arr[l];
			arr[l]=arr[r];
			arr[r]=temp;
			
			if(arr[l]==pivot)--r;
			if(arr[r]==pivot)++l;
			
		}
		if(l==r){
			l++;
			r--;
		}
		if(left<r) sort(left,r,arr);
		if(right>l) sort(l,right,arr);
	}
	public static void main(String[] args) {
		int len=12;
		int[] arr=new int[len];
		for(int i=0;i<len;i++){
			int t=(int)(Math.random()*100);
			arr[i]=t;
		}
		System.out.println(Calendar.getInstance().getTime());
		sort(0,len-1,arr);
		System.out.println(Calendar.getInstance().getTime());
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i]+",");
		}
		
	}
}
